package com.atozsoft.wf;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.gocom.components.coframe.tools.IconCls;

import com.eos.system.annotation.Bizlet;

import commonj.sdo.DataObject;

public class ConvertProcessClassData {
	/**
	 * 数据库实体转换为List
	 * @param processClass 数据库查询后的数据集
	 * @param nodeType 用作判断是否是第一次加载
	 * @return 转换后的List
	 * <P>作成者：houfy
	 * <P>作成日：2014-11-13
	 */
	@Bizlet("getProcessClassRoot")
	public List<Map<String, Object>> getProcessClassRoot(DataObject[] classes, String nodeType) {
		List<Map<String, Object>> rootList = new ArrayList<Map<String,Object>>();
		if(nodeType == null)
		{
			Map<String,Object> rootMap=new HashMap<String, Object>();
			rootMap.put("id", "0");
			rootMap.put("text", Constant.PROCESSCLASS_TREE_ROOT);
			rootMap.put("type", "root");
			//rootMap.put("buid", "");
			rootMap.put("iconCls", IconCls.MENU_ROOT);
			rootMap.put("isLeaf", false);
			rootMap.put("expanded", true);
			rootList.add(rootMap);
		}
		
		//构造应用List
		for(DataObject dataObject : classes){
			Map<String,Object> map=new HashMap<String, Object>();
			map.put("id", dataObject.get("nodeid"));
			map.put("text", dataObject.get("nodename"));
			map.put("pid", dataObject.get("parentid"));
			//map.put("buid", dataObject.get("buid"));
			map.put("iconCls", IconCls.MENU);
			
			//是否为叶子节点
			if(dataObject.get("isleaf").equals("1")){
				map.put("type", Constant.TYPE_MENU);
				map.put("expanded", false);
			}else{
				map.put("type", Constant.TYPE_MENUGROUP);
				map.put("expanded", false);
			}
			rootList.add(map);
		}
		return rootList;
	}
}
